public class MyQueue {

    //
    static class ListNode {
        public int value;//值
        public ListNode next;//下一个节点的地址

        public ListNode(int value) {
            this.value = value;
        }
    }

    public ListNode head;//头节点
    public ListNode last;//尾节点

    public int usedSize;

    //入队列
    public void offer(int value) {
        ListNode node = new ListNode(value);
        if(head == null) {
            head = node;
            last = node;
        } else {
            last.next = node;
            last = last.next;
        }
        usedSize++;
    }
    //获取队列中有效元素个数
    public int getUsedSize() {
        return usedSize;
    }
    //弹出一个元素
    public int poll() {
        if(head == null) {
            return -1;
        }
        int val = -1;
        if(head.next == null) {
            val = head.value;
            head = null;
            last = null;
            usedSize--;
            return val;
        }
        val = head.value;
        head = head.next;
        usedSize--;
        return val;
    }
    //获取对头元素
    public int peek() {
        if(head == null) {
            return -1;
        }
        return head.value;
    }


}
